#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int n, m, l, r;
int a[N];
struct Cnt {
  map<int, int> cnt;
  int num;
  Cnt() { num = 0; }
  void add(int x) {
    if (++cnt[x] == 1) num++;
  }
  void del(int x) {
    if (!--cnt[x]) num--;
  }
};
void solve() {
  cin >> n >> m >> l >> r;
  rep(i, 1, n) cin >> a[i];
  Cnt mn, mx;
  ll sum = 0;
  for (int i = 1, j = 1, k = 1; i <= n; i++) {
    while (j <= n && mn.num < m) mn.add(a[j++]);
    while (k <= n && mx.num <= m) mx.add(a[k++]);
    if (mn.num == m) {
      int x = j, y = mx.num > m ? k - 1 : k;
      x = max(x, i + l);
      y = min(y, i + r);
      sum += max(0, y - x + 1);
    } else
      break;
    mn.del(a[i]);
    mx.del(a[i]);
  }
  cout << sum << endl;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}